<template>

        <div id="cardBody">
        <div class="card" v-for="pet in petStore.showPetList">
            <div class="photo">
                <image-preview :src="pet.petImages" :width="`100%`" :height="`100%`"/>
            </div>
            <h1>{{pet.petName}}</h1>
            <div class="cardText">
<!--                <p>名字：{{pet.petName}}，性别：{{pet.petSex}}，品种：{{pet.petKind}}。</p>-->
                <p>{{pet.petText}}。
                    <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;
                    <span @click="gotoPetInfo( `${pet.petId}`)">了解更多</span></p>

    </div>

        </div>

    </div>


</template>

<script setup lang="ts">

    import usePetStore from "@/store/modules/pet";
    const petStore = usePetStore()
    petStore.show()

    import { useRouter, useRoute } from "vue-router";
    const route = useRoute();
    const router = useRouter();

    import useCustomerStore from '@/store/modules/customer.js'
    import { ref } from "vue";
    import { getToken } from '@/utils/auth.js'

    const customerStore = useCustomerStore()
    // const redirect = ref(undefined);
    const gotoPetInfo = (id:number) =>{
        console.log("==========goto info")
        if(getToken()){
            console.log(id)
            router.push("/petInfo/"+id);
        }else{
            alert("请先注册、登录！")
        }
    }
</script>

<style scoped>


    * {
        margin: 0;
        padding: 0;
    }

    html {
        font-size: 10px;
    }


    #cardBody{
        display: grid;
        grid-template-columns:1fr 1fr;
        column-gap: 10px;
        row-gap: 1em;
        margin-bottom: 20px;
        /*margin-left: 20px;*/
        /*background-color: #38bed1;*/
    }

    .card {
        /*background-color: #42b983;*/
        position: relative;
        width: 400px;
        height: 300px;
        overflow: hidden;
        margin: 30px 0px 0px 40px;
        border-radius: 20px;
        /*display: flex;*/
        justify-content: flex-start;
        align-items: center;
        /* flex子元素纵向排列 */
        flex-direction: column;
        /* 增加一个阴影 */
        box-shadow: 0 0 30px #2c2c2c;
        /* 给字体一个颜色 */
        color: #000000;
    }

    .photo{
        position: absolute;
        /* 默认为放大 */
        width: 400px;
        height: 300px;
        overflow: hidden;
        transition: 0.5s;
    }
    .photo::before{
        /* 通过before增加渐变背景实现遮罩，看起来清晰一些 */
        position: absolute;
        content: '';
        width: 100%;
        height: 100%;
        background-image: linear-gradient(to top,#333,transparent);
    }
    .card:hover .photo::before{
        /* 缩小时隐藏 */
        display: none;
    }



    /* 鼠标移动到上面变小 */
    .card:hover .photo{
        width: 80px;
        height: 60px;
        top: 10px;
        left: 10px;
        border-radius: 50%;
        box-shadow: 0 0 20px #111;
    }
    h1{
        position: absolute;
        top: 240px;
        left: 20px;
        transition: 0.5s;
    }
    .card:hover h1{
        position: absolute;
        top: 22px;
        left: 99px;
    }

    .cardText{
            margin: 80px 5px 5px 8px;
        white-space: normal;
    }
    /*p:nth-child(1){*/
    /*    width: 90%;*/
    /*    !* 段落缩进2个字符大小 *!*/
    /*    text-indent: 2em;*/
    /*    font-size: 16px;*/
    /*    margin-top: 80px;*/
    /*    line-height: 30px;*/
    /*}*/

    .cardText span:hover{
        color:blue;
        cursor: pointer;
        /*background-color:blue;*/
    }



</style>
